package com.wgy.day42.数据库连接池.druid工具类;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/*
使用新的JDBC工具类演示: 完成 添加操作,给account表添加一条数据
*/
public class Demo04Druid {
    public static void main(String[] args) {
        //完成添加操作,给account表添加一条数据
        Connection conn=null;
        PreparedStatement pstmt=null;
        try {
            //1.获取连接
          conn = JDBCUtils.getConnection();
            //2.定义SQL
            String sql="insert into account values(null,?,?) ";
            //3.获取执行SQL对象
            pstmt = conn.prepareStatement(sql);
            //4.给?号设置值
            pstmt.setString(1,"wangwu");
            pstmt.setDouble(2,5000);
            //5.执行SQL
            int count = pstmt.executeUpdate();
            System.out.println(count);

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally{
            JDBCUtils.close(pstmt,conn);
        }


    }
}
